﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using log4net;
using System.Reflection;

namespace AnyOffice.general.vehicle.maintenance
{
    public partial class _new : ModulePage
    {

        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DataTable table = new VehicleDao().SelectAll(base.Conn);
                this.ddlVehicleId.DataSource = table;
                this.ddlVehicleId.DataValueField = "VehicleId";
                this.ddlVehicleId.DataTextField = "Number";
                this.ddlVehicleId.DataBind();
                this.txtRequestDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                VehicleMaintenanceDao dao2 = new VehicleMaintenanceDao();
                VehicleMaintenanceData data = new VehicleMaintenanceData();
                data.VehicleId = Convert.ToInt32(this.ddlVehicleId.SelectedValue);
                if (this.txtRequestDate.Text != string.Empty)
                {
                    data.RequestDate = Convert.ToDateTime(this.txtRequestDate.Text);
                }
                data.Type = this.ddlType.SelectedValue;
                if (this.txtReason.Text != string.Empty)
                {
                    data.Reason = this.txtReason.Text;
                }
                if (this.txtPerson.Text != string.Empty)
                {
                    data.Person = this.txtPerson.Text;
                }
                if (this.txtFee.Text != string.Empty)
                {
                    data.Fee = Convert.ToDecimal(this.txtFee.Text);
                }
                if (this.txtRemark.Text != string.Empty)
                {
                    data.Remark = this.txtRemark.Text;
                }
                try
                {
                    dao2.Insert(base.Conn, data);
                    this.litMessage.Text = base.ShowPrompt("车辆维护记录保存成功！", "new.aspx");
                }
                catch (Exception exception)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception);
                    }
                    this.litMessage.Text = base.ShowPrompt("车辆维护记录保存失败！", "new.aspx");
                }
            }
        } 

    }
}
